package com.lft.juc03.lock8;

import java.util.concurrent.TimeUnit;

/**
 * 线程8锁——锁1
 * 两个普通同步方法。<br/>
 * 锁的是同一个对象。谁先持有锁，谁先执行。<br/>
 */
public class Lock1 {
	public static void main(String[] args) {
		Phone1 phone = new Phone1();
		new Thread(() -> {phone.senSms();}, "A").start();
		try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
		new Thread(() -> {phone.call();}, "B").start();
	}
}

class Phone1 {
	public synchronized void senSms() {
		// try {TimeUnit.SECONDS.sleep(2);} catch (InterruptedException e) {e.printStackTrace();}
		System.out.println(Thread.currentThread().getName() + " 发短信");
	}
	
	public synchronized void call() {
		System.out.println(Thread.currentThread().getName() + " 打电话");
	}
}